package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-21
 * Time: 17:26
 */
public class ReturnOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书:");
        //让用户输入书名信息:
        System.out.println("请输入你要归还的图书名称:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentNum = bookList.getBookNum();
        for (int i = 0; i < currentNum; i++) {
            //逐个判断name是否等于books的第i个元素
            Book book = bookList.getBooks(i);
            //这里找到了书架里同书名的书籍信息
            if(book.getName().equals(name)) {
                book.setBorrowed(false);
                System.out.println("归还成功!!!");
                return;
            }
        }
        //这里循环结束，如果执行到这里说明没有相同的书籍信息
        System.out.println("你归还的《" + name + "》的书籍信息不是我馆藏品!");
        System.out.println();
    }
}
